home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 76 / DVD Actual 1 Marzo 2003.iso / Trial / TurboCAD 7.1 Pro / Data.Cab / F25143_Preview.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-11-10  |  40.0 KB  |  1,191 lines

  1. unit Preview;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ComCtrls, ExtCtrls, FileCtrl, Menus, Grids, Buttons;
  8.  
  9. type
  10.   TPreviewForm = class(TForm)
  11.     ButtonQuit: TButton;
  12.     LoadTCFile: TButton;
  13.     OpenDrawingFileDialog: TOpenDialog;
  14.     StatusBar: TStatusBar;
  15.     ButtonZoomMinus: TButton;
  16.     CBDisplayDrawingName: TComboBox;
  17.     PaintBox1: TPaintBox;
  18.     HorizontalScrollBar: TScrollBar;
  19.     VerticalScrollBar: TScrollBar;
  20.     Label2: TLabel;
  21.     Label3: TLabel;
  22.     ButtonZoomPlus: TButton;
  23.     ButtonDraw: TButton;
  24.     PopupMenu1: TPopupMenu;
  25.     Circle1: TMenuItem;
  26.     Line1: TMenuItem;
  27.     ButtonNew: TButton;
  28.     ButtonShowProperties: TButton;
  29.     ButtonCircle: TSpeedButton;
  30.     ButtonSpline: TSpeedButton;
  31.     ButtonLine: TSpeedButton;
  32.     ButtonStar: TSpeedButton;
  33.     ButtonPickPoint: TSpeedButton;
  34.     StatusBar1: TStatusBar;
  35.  
  36.     procedure FormCreate(Sender: TObject);
  37.     procedure FormDestroy(Sender: TObject);
  38.     procedure ButtonQuitClick(Sender: TObject);
  39.     procedure PaintBox1Paint(Sender: TObject);
  40.     procedure LoadTCFileClick(Sender: TObject);
  41.     procedure LoadTCFileMouseDown(Sender: TObject; Button: TMouseButton;
  42.       Shift: TShiftState; X, Y: Integer);
  43.     procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
  44.       Shift: TShiftState; X, Y: Integer);
  45.     procedure VerticalScrollBarScroll(Sender: TObject;
  46.       ScrollCode: TScrollCode; var ScrollPos: Integer);
  47.     procedure HorizontalScrollBarScroll(Sender: TObject;
  48.       ScrollCode: TScrollCode; var ScrollPos: Integer);
  49.     procedure ButtonZoomPlusClick(Sender: TObject);
  50.     procedure ButtonZoomMinusClick(Sender: TObject);
  51.     procedure ButtonZoomMouseDown(Sender: TObject;
  52.       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  53.     procedure ButtonClearClick(Sender: TObject);
  54.     procedure ButtonDrawClick(Sender: TObject);
  55.     procedure ButtonNewClick(Sender: TObject);
  56.     procedure Circle1Click(Sender: TObject);
  57.     procedure Line1Click(Sender: TObject);
  58.     procedure ButtonShowPropertiesClick(Sender: TObject);
  59.     procedure PaintBox1DragOver(Sender, Source: TObject; X, Y: Integer;
  60.       State: TDragState; var Accept: Boolean);
  61.     procedure PaintBox1EndDrag(Sender, Target: TObject; X, Y: Integer);
  62.     procedure ButtonLineClick(Sender: TObject);
  63.     procedure ButtonCircleClick(Sender: TObject);
  64.     procedure ButtonSplineClick(Sender: TObject);
  65.     procedure ButtonStarClick(Sender: TObject);
  66.     procedure ButtonPickPointClick(Sender: TObject);
  67.     procedure PaintBox1StartDrag(Sender: TObject;
  68.       var DragObject: TDragObject);
  69.  
  70.   private
  71.     { Private declarations }
  72.   public
  73.     { Public declarations }
  74.     SDKApp : Variant;  { the overall OLE application object }
  75.     SDKViews: Variant; { the overall SDK  View object }
  76.     TheView: Variant; { the particuler instance of the view }
  77.     SDKDrawings : Variant; { the overall SDK Drawing }
  78.     TheDrawing : Variant; { the particular instance of the drawing }
  79.     Graphics, pIGraphic: Variant; { Graphic variants used for drawing on screen }
  80.     TCFileName : String;
  81.     ViewLeft, ViewTop, ViewWidth, ViewHeight: Double;  { View coordinates }
  82.     ScrollCenterX, ScrollCenterY: Double; { Dead center for scrolling }
  83.     ScrollRangeX, ScrollRangeY: Double; { Scroll range }
  84.     xStart, yStart: Double;  { Coordinates of start point of draw object }
  85.     DragStarted: Boolean;
  86.     SplineStarted: Boolean;
  87.     PointPicked: Boolean;
  88.     SelectedGraphic: Variant;
  89.     procedure LoadTheDrawing(FileName: String);
  90.     procedure ViewSetScrollPos;
  91.     procedure UpdateScrollParams;
  92.     procedure ViewZoomBy(Factor: Double);
  93.     procedure ViewScrollBy(DeltaX: Double; DeltaY: Double);
  94.     procedure PaintBoxRePaint;
  95.     procedure NewDrawing;
  96.   end;
  97.  
  98.  
  99. var
  100.   PreviewForm: TPreviewForm;
  101.  
  102. implementation
  103.  
  104. {$R *.DFM}
  105.  
  106. uses OleAuto, PopUp, Properties;
  107.  
  108. function VarValid(AVar: Variant): Boolean;
  109. begin
  110.     Result := (VarType(AVar) <> varEmpty) and (not VarIsNull(AVar));
  111. end;
  112.  
  113. procedure TPreviewForm.FormCreate(Sender: TObject);
  114. begin
  115.      SDKApp := NULL;
  116.      SDKViews := NULL;
  117.      TheView := NULL;
  118.      SDKDrawings := NULL;
  119.      TheDrawing := NULL;
  120.      SelectedGraphic := NULL;
  121.      { Create the  OLE link to the TC SDK Application }
  122.      SDKApp := CreateOleObject('IMSIGX.Application');
  123.      SDKDrawings := SDKApp.Drawings;  { Get the Drawings Collection to hold our drawings }
  124.      TCFileName := '';
  125.      DragStarted := false;
  126.      SplineStarted := false;
  127.      PointPicked := false;
  128.      NewDrawing;   { set up a new drawing }
  129. end;
  130.  
  131. procedure TPreviewForm.FormDestroy(Sender: TObject);
  132. begin
  133.  
  134.      if VarValid(TheView) then VarClear(TheView);
  135.      if VarValid(SDKViews) then VarClear(SDKViews);
  136.      if VarValid(pIGraphic) then VarClear(pIGraphic);
  137.  
  138.      if VarValid(TheDrawing) then
  139.      begin
  140.          TheDrawing.Close;
  141.          VarClear(TheDrawing);
  142.      end;
  143.  
  144.      if VarValid(SDKDrawings) then VarClear(SDKDrawings);
  145.      if VarValid(SDKApp) then VarClear(SDKApp);
  146. end;
  147.  
  148. procedure TPreviewForm.ButtonQuitClick(Sender: TObject);
  149. begin
  150.    close;
  151. end;
  152.  
  153. procedure TPreviewForm.PaintBox1Paint(Sender: TObject);
  154. begin
  155.      PaintBoxRePaint;
  156. end;
  157.  
  158. procedure TPreviewForm.LoadTCFileClick(Sender: TObject);
  159. var nItem: Integer;
  160. begin
  161.   { Turn off spline }
  162.   SplineStarted := false;
  163.   DragStarted := false;
  164.  
  165.   TCFileName := '';
  166.   { load the drawing from a group of files in a directory }
  167.   { First display Dialog file selection and choose from available files }
  168.   if OpenDrawingFileDialog.Execute then
  169.   begin
  170.  
  171.     TCFileName := OpenDrawingFileDialog.FileName;
  172.     PreviewForm.Caption := OpenDrawingFileDialog.FileName;
  173.     nItem := CBDisplayDrawingName.Items.Add(OpenDrawingFileDialog.FileName);
  174.     CBDisplayDrawingName.ItemIndex := nItem;
  175.     if pos('.tcw', TCFileName) > 2 then
  176.        LoadTheDrawing(TCFileName);
  177.  
  178.     StatusBar.SimpleText := 'Right click on button, object or screen to see the code for the procedure';
  179.   end;
  180. end;
  181.  
  182. { Note: this will be replaced by simple call to TheView.ZoomBy when it is }
  183. { added to the SDK. }
  184. procedure TPreviewForm.ViewZoomBy(Factor: Double);
  185. var
  186.    CanvasDC: HDC;
  187.    VCenterX, VCenterY: Double;
  188.    ViewChanged: Boolean;
  189. begin
  190.     if VarValid(TheDrawing) and VarValid(TheView) then
  191.     begin
  192.         ViewChanged := False;
  193.  
  194.         { Obtain the Device Context for the PaintBox canvas. }
  195.         CanvasDC := PaintBox1.Canvas.Handle;
  196.         TheView.Update := False;  { Delay update until we tell it to. }
  197.         TheView.DC := CanvasDC;
  198.         TheView.MappingMode := MM_TEXT;
  199.         TheView.FixedAspectRatio := TRUE;
  200.  
  201.         { See if we need to start over. }
  202.         if (Factor <= 0.0) or ((ViewWidth = 0) and (ViewHeight = 0)) then
  203.         begin
  204.            { Factor <= 0.0 means reset.  Otherwise, initial settings. }
  205.            TheView.ScreenLeft := 0.0;
  206.            TheView.ScreenTop :=  0.0;
  207.            TheView.ScreenWidth := PaintBox1.Width;
  208.            TheView.ScreenHeight := PaintBox1.Height;
  209.            TheView.ZoomToExtents;
  210.            ViewLeft := TheView.ViewLeft;
  211.            ViewTop := TheView.ViewTop;
  212.            ViewWidth := TheView.ViewWidth;
  213.            ViewHeight := TheView.ViewHeight;
  214.            ViewChanged := True;
  215.         end;
  216.  
  217.         if (Factor > 0.0) and (Factor <> 1.0) then
  218.         begin
  219.            { Keep the center fixed, and change view coordinates. }
  220.            VCenterX := ViewLeft + (ViewWidth/2.0);
  221.            VCenterY := ViewTop - (ViewHeight/2.0);
  222.            ViewWidth := ViewWidth / Factor;
  223.            ViewHeight := ViewHeight / Factor;
  224.            ViewLeft := VCenterX - (ViewWidth/2.0);
  225.            ViewTop := VCenterY + (ViewHeight/2.0);
  226.            ViewChanged := True;
  227.         end;
  228.  
  229.         { Synchronize the view to our new location and zoom. }
  230.         TheView.ViewLeft := ViewLeft;
  231.         TheView.ViewTop := ViewTop;
  232.         TheView.ViewWidth := ViewWidth;
  233.         TheView.ViewHeight := ViewHeight;
  234.  
  235.         { Update display. }
  236.         PaintBoxRePaint;
  237.  
  238.         { Keep scroll bars in sync. }
  239.         if ViewChanged then UpdateScrollParams;
  240.     end;
  241. end;
  242.  
  243. { this loads the drawing from the disk using IMSI SDK }
  244. procedure  TPreviewForm.LoadTheDrawing(FileName: String);
  245. const
  246.   MM_TEXT = 1;
  247. var
  248.     var1, var2: Variant;
  249.     canvasRect: TRect;
  250.     EVar: String;
  251. begin
  252.    if VarValid(SDKApp) and (FileName <> '') then
  253.    begin
  254.        try
  255.        begin
  256.            var1 := null;
  257.            var2 := null;
  258.  
  259.            PaintBox1.Canvas.Brush.Color := clWhite;
  260.            canvasRect := Rect(0, 0, PaintBox1.Width, PaintBox1.Width);
  261.            PaintBox1.Canvas.FillRect(canvasRect);
  262.  
  263.            {  Close any previous open drawings }
  264.            if VarValid(TheView) then
  265.            begin
  266.               VarClear(TheView);
  267.               TheView := NULL;
  268.            end;
  269.  
  270.            if VarValid(SDKViews) then
  271.            begin
  272.               VarClear(SDKViews);
  273.               SDKViews := NULL;
  274.            end;
  275.  
  276.            if VarValid(TheDrawing) then
  277.            begin
  278.                TheDrawing.Close(false);
  279.                VarClear(TheDrawing);
  280.                TheDrawing := NULL;
  281.            end;
  282.  
  283.            { open the graphic TCW file using the SDK method }
  284.            TheDrawing := SDKDrawings.Open(FileName);
  285.            SDKViews := TheDrawing.Views;
  286.            TheView := SDKViews.Add();
  287.  
  288.            { now that we have the particular view for the drawing, call the our
  289.              repaint procedure to handle the painting using the SDK, we set
  290.              the new global coordinates to accomplish the painting }
  291.            { ViewWidth = 0.0 and ViewHeight = 0.0 mean initial settings }
  292.            ViewWidth := 0.0;
  293.            ViewHeight := 0.0;
  294.            ViewLeft := 0.0;
  295.            ViewTop := 0.0;
  296.  
  297.            ViewZoomBy(0.0);   { Specifying 0.0 as the zoom factor redraws... }
  298.        end;
  299.        except
  300.           on E:Exception do
  301.               MessageDlg('Exception Occurred: ' + E.Message, mtInformation, [mbOk], 0);
  302.        end;
  303.    end;
  304. end;
  305.  
  306. procedure TPreviewForm.LoadTCFileMouseDown(Sender: TObject;
  307.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  308. begin
  309.    if Button = mbRight then
  310.    begin
  311.        FormPopUp.Top := PreviewForm.ClientOrigin.Y + (Sender as TButton).Top + (Sender as TButton).Height + 5;
  312.        FormPopUp.Left := (PreviewForm.ClientOrigin.X + (Sender as TButton).Left + X) - (FormPopUp.Width div 2);
  313.        FormPopUp.SetFileName('LoadFile.rtf');
  314.        FormPopUp.show;
  315.    end;
  316.  
  317. end;
  318.  
  319. procedure TPreviewForm.PaintBox1MouseDown(Sender: TObject;
  320.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  321. var vX, vY: Double;
  322.     DispText: String;
  323. begin
  324.    if Button = mbRight then
  325.    begin
  326.        FormPopUp.Top := PreviewForm.ClientOrigin.Y + Y + (Sender as TPaintBox).Top + 5;
  327.        FormPopUp.Left := (PreviewForm.ClientOrigin.X + X) - (FormPopUp.Width div 2);
  328.        FormPopUp.SetFileName('CreateForm.rtf');
  329.        FormPopUp.show;
  330.    end;
  331.    if Button = mbLeft then
  332.    begin
  333.       DispText :=  'X: ' + IntToStr(X) + '   Y: ' + IntToStr(Y);
  334.       if VarValid(TheDrawing) and VarValid(TheView) then
  335.       begin
  336.          TheView.ScreenToView(X, Y, vX, vY);
  337.          DispText := DispText + '   View -> X: ' + FloatToStr(vX) + '   Y: ' + FloatToStr(vY);
  338.          DispText := DispText + '   VL: ' + FloatToStr(TheView.ViewLeft);
  339.           {'  VT: ' + FloatToStr(TheView.ViewTop) + '  VW: ' + FloatToStr(TheView.ViewWidth) +
  340.           '  VH: ' + FloatToStr(TheView.ViewHeight);
  341.           }
  342.          if ButtonCircle.Down then
  343.          begin
  344.              Graphics := TheDrawing.Graphics;  { get the graphic to start drawing }
  345.              xStart := X;
  346.              yStart := Y;
  347.          end
  348.          else if ButtonLine.Down then
  349.          begin
  350.          end;
  351.  
  352.       end;
  353.       StatusBar.SimpleText := DispText;
  354.    end;
  355. end;
  356.  
  357. { Should be called whenever Drawing's bounding box, or Viewport is changed. }
  358. procedure TPreviewForm.UpdateScrollParams;
  359. var
  360.    VarDummy: Variant;
  361.    BBox, BoxMin, BoxMax: Variant;
  362.    X1, Y1, X2, Y2: Double;
  363.    Delta1, Delta2: Double;
  364. begin
  365.     Label2.Visible := True;
  366.     Label3.Visible := True;
  367.  
  368.     HorizontalScrollBar.Visible := True;
  369.     HorizontalScrollBar.Min := 0;
  370.     HorizontalScrollBar.Max := 32000;
  371.     HorizontalScrollBar.LargeChange := 3200;
  372.     HorizontalScrollBar.SmallChange := 320;
  373.  
  374.     VerticalScrollBar.Visible := True;
  375.     VerticalScrollBar.Min := 0;
  376.     VerticalScrollBar.Max := 32000;
  377.     VerticalScrollBar.LargeChange := 3200;
  378.     VerticalScrollBar.SmallChange := 320;
  379.  
  380.     { Arbitrary limits if all else fails. }
  381.     ScrollCenterX := 0.0;
  382.     ScrollCenterY := 0.0;
  383.     ScrollRangeX := 1.0;
  384.     ScrollRangeY := 1.0;
  385.     if VarValid(TheDrawing) then
  386.     begin
  387.          X1 := ViewLeft;
  388.          Y1 := ViewTop - ViewHeight;
  389.          X2 := ViewLeft + ViewWidth;
  390.          Y2 := ViewTop;
  391.          try
  392.              { Set ScrollCenter to center of drawing's graphics. }
  393.              Graphics := TheDrawing.Graphics;
  394.  
  395.              TVarData(varDummy).VType := varError;
  396.              TVarData(varDummy).VError := DISP_E_PARAMNOTFOUND;
  397.              BBox := Graphics.CalcBoundingBox( VarDummy );
  398.  
  399.              if not BBox.Empty then
  400.              begin
  401.                 BoxMin := BBox.Min;
  402.                 BoxMax := BBox.Max;
  403.                 X1 := BoxMin.X;
  404.                 Y1 := BoxMin.Y;
  405.                 X2 := BoxMax.X;
  406.                 Y2 := BoxMax.Y;
  407.                 ScrollCenterX := (X1 + X2)/2.0;
  408.                 ScrollCenterY := (Y1 + Y2)/2.0;
  409.  
  410.                 { Set min and max for range to include current viewport. }
  411.                 if ViewLeft < X1 then X1 := ViewLeft;
  412.                 if (ViewTop - ViewHeight) < Y1 then Y1 := ViewTop - ViewHeight;
  413.                 if (ViewLeft + ViewWidth) > X2 then X2 := ViewLeft + ViewWidth;
  414.                 if ViewTop > Y2 then Y2 := ViewTop;
  415.              end;
  416.          except
  417.          end;
  418.  
  419.          { Set ScrollRange based on largest area included. }
  420.          Delta1 := ScrollCenterX - X1;
  421.          Delta2 := X2 - ScrollCenterX;
  422.          if Delta1 > Delta2 then ScrollRangeX := 2.0 * Delta1
  423.          else ScrollRangeX := 2.0 * Delta2;
  424.  
  425.          Delta1 := ScrollCenterY - Y1;
  426.          Delta2 := Y2 - ScrollCenterY;
  427.          if Delta1 > Delta2 then ScrollRangeY := 2.0 *Delta1
  428.          else ScrollRangeY := 2.0 * Delta2;
  429.     end;
  430.     ViewSetScrollPos;
  431. end;
  432.  
  433. function MyRound(D: Double): Integer;
  434. var
  435.    ConvertString: String;
  436. begin
  437.      ConvertString := FloatToStrF(D, ffFixed, 18, 0);
  438.      Result := StrToInt(ConvertString);
  439. end;
  440.  
  441. procedure TPreviewForm.ViewSetScrollPos;
  442. var
  443.    VCenter: Double;
  444.    IMax: Integer;
  445.    DMax: Double;
  446.    DPos: Double;
  447.    IPos: Integer;
  448. begin
  449.      if ScrollRangeX > 0.0 then
  450.      begin
  451.           IMax := HorizontalScrollBar.Max;
  452.           DMax := IMax;
  453.           VCenter := ViewLeft + (ViewWidth / 2.0);
  454.           DPos := (DMax / 2.0) +
  455.               DMax * (VCenter - ScrollCenterX)/ScrollRangeX;
  456.  
  457.           if DPos <= 0.0 then IPos := 0
  458.           else if DPos >= DMax then IPos := IMax
  459.           else IPos := MyRound(DPos);
  460.           HorizontalScrollBar.Position := IPos;
  461.      end;
  462.  
  463.      if ScrollRangeY > 0.0 then
  464.      begin
  465.           IMax := VerticalScrollBar.Max;
  466.           DMax := IMax;
  467.           VCenter := ViewTop - (ViewHeight / 2.0);
  468.           DPos := (DMax / 2.0) +
  469.               DMax * (VCenter - ScrollCenterY)/ScrollRangeY;
  470.  
  471.           if DPos < 0.0 then IPos := 0
  472.           else if DPos > DMax then IPos := IMax
  473.           else IPos := MyRound(DPos);
  474.           VerticalScrollBar.Position := IPos;
  475.      end;
  476. end;
  477.  
  478. procedure TPreviewForm.ViewScrollBy(DeltaX: Double; DeltaY: Double);
  479. begin
  480.     ViewLeft := ViewLeft + DeltaX;
  481.     ViewTop := ViewTop + DeltaY;
  482.     ViewZoomBy(1.0);
  483. end;
  484.  
  485. procedure TPreviewForm.VerticalScrollBarScroll(Sender: TObject;
  486.   ScrollCode: TScrollCode; var ScrollPos: Integer);
  487. var
  488.    Y, YOrig: Double;
  489.    DPos, DMax: Double;
  490. begin
  491.     if VarValid(TheDrawing) and VarValid(TheView) then
  492.     begin
  493.         Y := ViewTop - (ViewHeight/2.0); { Center point of view. }
  494.         YOrig := Y;
  495.  
  496.         case ScrollCode of
  497.            scLineUp:   Y := Y + (ViewHeight/32.0);  { scroll in the +Y direction }
  498.            scPageUp:   Y := Y + (ViewHeight/8.0);  { scroll in the +Y direction }
  499.            scLineDown: Y := Y - (ViewHeight/32.0);  { scroll in the -Y direction }
  500.            scPageDown: Y := Y - (ViewHeight/8.0);  { scroll in the -Y direction }
  501.            scTrack:
  502.                begin
  503.                     DPos := ScrollPos;
  504.                     DMax := VerticalScrollBar.Max;
  505.                     Y := ScrollCenterY -
  506.                       (DPos / DMax - 0.5) * ScrollRangeY;
  507.                end
  508.            else Exit;
  509.         end;
  510.  
  511.         ViewScrollBy(0.0, Y - YOrig);
  512.     end;
  513. end;
  514.  
  515. procedure TPreviewForm.HorizontalScrollBarScroll(Sender: TObject;
  516.   ScrollCode: TScrollCode; var ScrollPos: Integer);
  517. var
  518.    X, XOrig: Double;
  519.    DPos, DMax: Double;
  520. begin
  521.     if VarValid(TheDrawing) and VarValid(TheView) then
  522.     begin
  523.         X := ViewLeft + (ViewWidth/2.0); { Center point of view. }
  524.         XOrig := X;
  525.  
  526.         case ScrollCode of
  527.            scLineUp:   X := X - (ViewWidth/32.0);  { scroll in the -X direction }
  528.            scPageUp:   X := X - (ViewWidth/8.0);  { scroll in the -X direction }
  529.            scLineDown: X := X + (ViewWidth/32.0);  { scroll in the +X direction }
  530.            scPageDown: X := X + (ViewWidth/8.0);  { scroll in the +X direction }
  531.            scTrack:
  532.                begin
  533.                     DPos := ScrollPos;
  534.                     DMax := HorizontalScrollBar.Max;
  535.                     X := ScrollCenterX +
  536.                       (DPos / DMax - 0.5) * ScrollRangeX;
  537.                end
  538.            else Exit;
  539.         end;
  540.  
  541.         ViewScrollBy(X - XOrig, 0.0);
  542.     end;
  543. end;
  544.  
  545. procedure TPreviewForm.ButtonZoomPlusClick(Sender: TObject);
  546. begin
  547.     { Turn off spline }
  548.     SplineStarted := false;
  549.     DragStarted := false;
  550.     
  551.     ViewZoomBy(1.414);
  552. end;
  553.  
  554. procedure TPreviewForm.ButtonZoomMinusClick(Sender: TObject);
  555. begin
  556.     { Turn off spline }
  557.     SplineStarted := false;
  558.     DragStarted := false;
  559.     
  560.     ViewZoomBy(0.707);
  561. end;
  562.  
  563. procedure TPreviewForm.ButtonZoomMouseDown(Sender: TObject;
  564.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  565. begin
  566.    if Button = mbRight then
  567.    begin
  568.        FormPopUp.Top := PreviewForm.ClientOrigin.Y + (Sender as TButton).Top + (Sender as TButton).Height + 5;
  569.        FormPopUp.Left := (PreviewForm.ClientOrigin.X + (Sender as TButton).Left + X) - (FormPopUp.Width div 2);
  570.        FormPopUp.SetFileName('zoom.rtf');
  571.        FormPopUp.show;
  572.    end;
  573. end;
  574.  
  575. { This procedure repaints the screen with the current picture }
  576. procedure TPreviewForm.PaintBoxRePaint;
  577. const
  578.   MM_TEXT = 1;
  579. var CanvasDC: HDC;
  580.     canvasRect: TRect;
  581.     ViewChanged: Boolean;
  582. begin
  583.     { clear the screen to white first }
  584.     canvasRect := Rect(0, 0, PaintBox1.Width, PaintBox1.Height);
  585.     PaintBox1.Canvas.Brush.Color := clWhite;
  586.     PaintBox1.Canvas.FillRect(canvasRect);
  587.     if VarValid(TheDrawing) and VarValid(TheView) then
  588.     begin
  589.         { obtain the Device Context for the paintBox canvas }
  590.         CanvasDC := PaintBox1.Canvas.Handle;
  591.  
  592.         TheView.Update := FALSE;  { delay update until we tell it to }
  593.         TheView.DC := CanvasDC;
  594.         TheView.MappingMode := MM_TEXT;
  595.         TheView.FixedAspectRatio := TRUE;
  596.  
  597.         ViewChanged := (ViewWidth = 0) and (ViewHeight = 0);
  598.         if ViewChanged then
  599.         begin
  600.            { Initial settings }
  601.            TheView.ScreenLeft := canvasRect.Left;
  602.            TheView.ScreenTop :=  canvasRect.Top;
  603.            TheView.ScreenWidth := canvasRect.Right - canvasRect.Left;
  604.            TheView.ScreenHeight := canvasRect.Bottom - canvasRect.Top;
  605.            TheView.ZoomToExtents;
  606.         end
  607.         else
  608.         begin
  609.            { Saved settings }
  610.            TheView.Refresh;
  611.         end;
  612.         ViewLeft := TheView.ViewLeft;
  613.         ViewTop := TheView.ViewTop;
  614.         ViewWidth := TheView.ViewWidth;
  615.         ViewHeight := TheView.ViewHeight;
  616.  
  617.         if ViewChanged then UpdateScrollParams;
  618.     end;
  619. end;
  620.  
  621. procedure TPreviewForm.ButtonClearClick(Sender: TObject);
  622. begin
  623.   { clear the screen of the any drawing }
  624.   PaintBox1.Canvas.Brush.Color := clWhite;
  625.   PaintBox1.Canvas.FillRect(Rect(0, 0, PaintBox1.Width, PaintBox1.Height));
  626.  
  627.   { remove any Variant association and close the drawing }
  628.   if VarValid(TheView) then
  629.   begin
  630.      VarClear(TheView);
  631.      TheView := NULL;
  632.   end;
  633.  
  634.   if VarValid(SDKViews) then
  635.   begin
  636.      VarClear(SDKViews);
  637.      SDKViews := NULL;
  638.   end;
  639.  
  640.   if VarValid(TheDrawing) then
  641.   begin
  642.       TheDrawing.Close(false);
  643.       VarClear(TheDrawing);
  644.       TheDrawing := NULL;
  645.   end;
  646.   UpdateScrollParams;
  647. end;
  648.  
  649. procedure TPreviewForm.ButtonDrawClick(Sender: TObject);
  650. begin
  651.   { Turn off spline }
  652.   SplineStarted := false;
  653.   DragStarted := false;
  654.  
  655.   PopupMenu1.AutoPopup := False;
  656.   PopupMenu1.Popup(PreviewForm.ClientOrigin.X + ButtonDraw.Left, PreviewForm.ClientOrigin.Y + ButtonDraw.Top + ButtonDraw.Height);
  657. end;
  658.  
  659. procedure TPreviewForm.ButtonNewClick(Sender: TObject);
  660. begin
  661.    { Turn off spline }
  662.    SplineStarted := false;
  663.    DragStarted := false;
  664.  
  665.    if VarValid(SDKApp) then
  666.    begin
  667.       NewDrawing;   { set up a new drawing }
  668.    end;
  669.  
  670. end;
  671.  
  672. procedure TPreviewForm.Circle1Click(Sender: TObject);
  673. var
  674.     xc, yc, zc, xp, yp, zp: double;
  675.     vh, vw, vl, vt, vx, vy: double;
  676.     vLeft, vTop: double;
  677. begin
  678.  
  679.     { turn off spline and drag }
  680.     SplineStarted := false;
  681.     DragStarted := false;
  682.  
  683.     { Circle from center }
  684.     { make sure that a drawing is ready for use }
  685.     if VarValid(TheView) and VarValid(TheDrawing) then
  686.     begin
  687.  
  688.         PaintBox1.Canvas.Brush.Color := clWhite;
  689.         PaintBox1.Canvas.FillRect(Rect(0, 0, PaintBox1.Width, PaintBox1.Height));
  690.  
  691.         xc := (TheView.ViewLeft + TheView.ViewWidth) / 2.0;
  692.         yc := (TheView.ViewTop - TheView.ViewHeight) / 2.0;
  693.         zc := 0.0;
  694.         xp := TheView.ViewLeft;
  695.         yp := TheView.ViewTop;
  696.         zp := 0.0;
  697.  
  698.         Graphics := TheDrawing.Graphics;
  699.         pIGraphic := Graphics.AddCircleCenterAndPoint(xc, yc, zc, xp, yp, zp);
  700.  
  701.         PaintBoxRePaint;
  702.         UpdateScrollParams;
  703.     end;
  704. end;
  705.  
  706. procedure TPreviewForm.Line1Click(Sender: TObject);
  707.     { draw a line on screen }
  708. var
  709.     xc, yc, zc, xp, yp, zp: double;
  710.     vh, vw, vl, vt: double;
  711. begin
  712.     { turn off spline and drag }
  713.     SplineStarted := false;
  714.     DragStarted := false;
  715.  
  716.    { Line from two points }
  717.     { make sure that a drawing is ready for use }
  718.     if VarValid(TheView) and VarValid(TheDrawing) then
  719.     begin
  720.         { clear screen first }
  721.         PaintBox1.Canvas.Brush.Color := clWhite;
  722.         PaintBox1.Canvas.FillRect(Rect(0, 0, PaintBox1.Width, PaintBox1.Height));
  723.  
  724.         { we need to draw in view coordinates not screen coordinates as the drawing
  725.           by default is in inches. Remember that the default is: inches with the screen
  726.           center as 0.0, 0.0}
  727.         xc := (TheView.ViewWidth) / 2.0;;
  728.         yc := 0.0;
  729.         zc := 0.0;
  730.         xp := (TheView.ViewLeft) + (TheView.ViewWidth / 2.0);
  731.         yp := 0.0;
  732.         zp := 0.0;
  733.  
  734.         xc := (TheView.ViewLeft + TheView.ViewWidth) / 2.0;
  735.         yc := (TheView.ViewTop - TheView.ViewHeight) / 2.0;
  736.         zc := 0.0;
  737.         xp := TheView.ViewLeft;
  738.         yp := TheView.ViewTop;
  739.  
  740.         Graphics := TheDrawing.Graphics;
  741.         pIGraphic := Graphics.AddLineSingle(xc, yc, zc, xp, yp, zp);
  742.  
  743.         PaintBoxRePaint;
  744.         UpdateScrollParams;
  745.     end;
  746. end;
  747.  
  748. procedure TPreviewForm.ButtonShowPropertiesClick(Sender: TObject);
  749. var pItem, pProps, ValueStr: Variant;
  750.     pTypeName, pName, TypeStr: String;
  751.     pType: Integer;
  752.     pValue: Variant;
  753.     Count, ii, TotalWidth: Integer;
  754.     isArray: Boolean;
  755.     Col0, Col1, Col2: Integer;
  756. begin
  757.    if VarValid(SDKApp) then
  758.    begin
  759.        pProps := NULL;
  760.        pProps := TheDrawing.Properties;
  761.        Count := pProps.Count;
  762.        Col0 := 0; Col1 := 0; Col2 := 0; TotalWidth := 0;
  763.        with FormProperties.StringGridProperties do
  764.        begin
  765.           Cells[0, 0] := 'Property';
  766.           if Canvas.TextWidth('Property') > Col0 then Col0 := Canvas.TextWidth('Property');
  767.           Cells[1, 0] := 'Type';
  768.           if Canvas.TextWidth('Type') > Col1 then Col1 := Canvas.TextWidth('Type');
  769.           Cells[2, 0] := 'Value';
  770.           if Canvas.TextWidth('Value') > Col2 then Col2 := Canvas.TextWidth('Value');
  771.           RowCount := 1;
  772.  
  773.           for ii:=0 to Count-1 do
  774.           begin
  775.               { This is the way to access a property which takes a parameter }
  776.               { Item(Parameter) must be used as an array Item[parameter] }
  777.               pItem := pProps.Item[ii];
  778.               RowCount := RowCount + 1;
  779.               { get the name of the property }
  780.               pName := pItem.Name;
  781.  
  782.               { find max width to set col, This uses the Canvas method TextWidth to
  783.                 find the string width in pixels }
  784.               if Canvas.TextWidth(pName) > Col0 then Col0 := Canvas.TextWidth(pName);
  785.  
  786.               Cells[0, ii+1] := pName;
  787.               { we need a try - exception here because the return may throw an exception on 'no value' }
  788.               try
  789.                  pType := pItem.Type;
  790.                  isArray := False;
  791.                  if (pType and varArray) <> 0 then
  792.                  begin
  793.                       isArray := True;
  794.                       pType := pType and (not varArray);
  795.                  end;
  796.  
  797.                  { we need to define what the TYPE means in english }
  798.                  case pType of
  799.                       varEmpty: { VT_EMPTY } pTypeName := 'Empty';
  800.                       varSmallint: { VT_I2 } pTypeName := 'Integer';
  801.                       varInteger: { VT_I4 } pTypeName := 'Long';
  802.                       varSingle: { VT_R4 } pTypeName := 'Real';
  803.                       varDouble: { VT_R8 } pTypeName := 'Double';
  804.                       varOleStr: { VT_BSTR } pTypeName := 'String';
  805.                       varBoolean: { VT_BOOL } pTypeName := 'Boolean';
  806.                       varByte: { VT_UI1 } pTypeName := 'Byte';
  807.                       else pTypeName := 'Unknown (' + IntToStr(pType) + ')';
  808.                   end;
  809.  
  810.                   { if an array type then add extra wording }
  811.                   if isArray then
  812.                   begin
  813.                      TypeStr := 'Array of ' + pTypeName;
  814.                      Cells[1, ii+1] := TypeStr;
  815.                      if Canvas.TextWidth(TypeStr) > Col1 then Col1 := Canvas.TextWidth(TypeStr);
  816.                   end
  817.                   else
  818.                   begin
  819.                      Cells[1, ii+1] := pTypeName;
  820.                      if Canvas.TextWidth(pTypeName) > Col1 then Col1 := Canvas.TextWidth(pTypeName);
  821.                   end;
  822.  
  823.               except
  824.                   Cells[1, ii+1] := 'Error';
  825.               end;
  826.  
  827.               try
  828.                   PValue := pItem.Value;
  829.                   if VarType(PValue) in [varSmallint, varInteger, varSingle, varDouble, varOleStr, varBoolean, varByte] then
  830.                      VarCast (ValueStr, pValue, varString)   { convert to string }
  831.                   else
  832.                      ValueStr := 'Unknown';
  833.  
  834.                   Cells[2, ii+1] := ValueStr;
  835.                   if Canvas.TextWidth(ValueStr) > Col2 then Col2 := Canvas.TextWidth(ValueStr);
  836.               except
  837.                   if Canvas.TextWidth('Error') > Col2 then Col2 := Canvas.TextWidth('Error');
  838.                   Cells[2, ii+1] := 'Error';
  839.               end;
  840.  
  841.           end;
  842.  
  843.  
  844.           ColWidths[0] := Col0 + 5;
  845.           ColWidths[1] := Col1 + 5;
  846.           ColWidths[2] := Col2 + 5;
  847.           TotalWidth := Col0 + Col1 + Col2 + 15;
  848.           Width := TotalWidth + 25;
  849.           FormProperties.Width := Width + 10;
  850.           FixedRows := 1;
  851.        end;
  852.  
  853.        FormProperties.show;
  854.        VarClear(pProps);
  855.        VarClear(pItem);
  856.    end;
  857. end;
  858.  
  859. procedure TPreviewForm.PaintBox1DragOver(Sender, Source: TObject; X,
  860.   Y: Integer; State: TDragState; var Accept: Boolean);
  861. var vX, vY: Double;
  862.     DispText: String;
  863.     TheStar: Variant;
  864. begin
  865.     DispText :=  'X: ' + IntToStr(X) + '   Y: ' + IntToStr(Y);
  866.     if VarValid(TheView) then
  867.     begin
  868.        if not DragStarted then
  869.        begin
  870.           if (ButtonCircle.Down) or (ButtonLine.Down) or (ButtonStar.Down) or (ButtonPickPoint.Down) then
  871.           begin
  872.  
  873.               { This starts the drawing fixing the first point as xStart and yStart }
  874.               { first get the view coordinates from the screen coordinates of the
  875.                 mouse click }
  876.               TheView.ScreenToView(X, Y, vX, vY);
  877.               Graphics := TheDrawing.Graphics;  { get the graphic to start drawing }
  878.               xStart := vX;
  879.               yStart := vY;
  880.               DragStarted := true;
  881.  
  882.               if ButtonPickPoint.Down then
  883.                   PointPicked := true;
  884.               { display in status box }
  885.               DispText := DispText + '   View -> X: ' + FloatToStr(vX) + '   Y: ' + FloatToStr(vY);
  886.               varClear(pIGraphic);
  887.           end
  888.           else if ButtonSpline.Down then
  889.           begin
  890.               if not SplineStarted then
  891.               begin
  892.                   TheView.ScreenToView(X, Y, vX, vY);
  893.                   Graphics := TheDrawing.Graphics;  { get the graphic to start drawing }
  894.                   xStart := vX;
  895.                   yStart := vY;
  896.                   DragStarted := true;
  897.  
  898.                   { display in status box }
  899.                   DispText := DispText + '   View -> X: ' + FloatToStr(vX) + '   Y: ' + FloatToStr(vY);
  900.               end;
  901.           end
  902.           else
  903.           begin
  904.               { no draw button down, so just display coordinates }
  905.               TheView.ScreenToView(X, Y, vX, vY);
  906.               DispText := DispText + '   View -> X: ' + FloatToStr(vX) + '   Y: ' + FloatToStr(vY);
  907.           end;
  908.        end
  909.        else { still dragging the mouse }
  910.        begin
  911.  
  912.           { if we wish to rubber bank the drawing object we have to erase the
  913.             previous object and draw the temporary object from new positions }
  914.  
  915.           { just display the coordinates to the StatusBox }
  916.           TheView.ScreenToView(X, Y, vX, vY);
  917.           DispText := DispText + '   View -> X: ' + FloatToStr(vX) + '   Y: ' + FloatToStr(vY);
  918.        end;
  919.     end;
  920.     { display coordinates of mouse to Status Box }
  921.     StatusBar.SimpleText := DispText;
  922. end;
  923.  
  924. procedure TPreviewForm.PaintBox1EndDrag(Sender, Target: TObject; X, Y: Integer);
  925. var  vX, vY: double;
  926.      pickCount, ii: Integer;
  927.      varX, varY, varZ: Double;
  928.      varDummy, ThePickedResults: Variant;
  929.      pIVertex, IVertices: Variant;
  930.      TheItem, PickGraphic, ThePenColor, pProp: Variant;
  931.  
  932. begin
  933.  
  934.     if (DragStarted = true) and VarValid(TheView) and
  935.        ((ButtonCircle.Down = true) or (ButtonLine.Down = true) or (ButtonSpline.Down = true) or
  936.         (ButtonStar.Down = true) or (ButtonPickPoint.Down = true)) then
  937.     begin
  938.  
  939.         { the user has now released the mouse button and we must draw the object with
  940.           the coordinates from this mouse point }
  941.  
  942.         { clear the screen first. This would not be necessary if the drawing scale wasn't changing }
  943.         PaintBox1.Canvas.Brush.Color := clWhite;
  944.         PaintBox1.Canvas.FillRect(Rect(0, 0, PaintBox1.Width, PaintBox1.Height));
  945.  
  946.         { get the view coordinates for the screen mouse position }
  947.         TheView.ScreenToView(X, Y, vX, vY);
  948.  
  949.         { with the start and ending coordinates we use the IMSI SDK to draw the circle line or slpine }
  950.         if ButtonCircle.Down = true then { draw circle center and radius point }
  951.             pIGraphic := Graphics.AddCircleCenterAndPoint(xStart, yStart, 0, vX, vY, 0)
  952.         else if ButtonLine.Down = true then  { drawing line start and end point }
  953.             pIGraphic := Graphics.AddLineSingle(xStart, yStart, 0, vX, vY, 0)
  954.         else if ButtonSpline.Down = true then { draw spline, start point and subsequent mouse drag points }
  955.         begin
  956.             { First two points on spline come from draw Over and here from End drag }
  957.             if not SplineStarted then { first time through with spline }
  958.             begin
  959.                 varX := xStart;
  960.                 varY := yStart;
  961.                 varZ := 0.0;
  962.                 pIGraphic := Graphics.AddCurveSpline(varX, varY, 0.0);
  963.                 SplineStarted := true;  { mark as starting spline for subsequent mouse clicks and drags }
  964.  
  965.                 TVarData(varDummy).VType := varError;
  966.                 TVarData(varDummy).VError := DISP_E_PARAMNOTFOUND;
  967.  
  968.                 IVertices := NULL;
  969.              IVertices := pIGraphic.Vertices;
  970.                 varX := vX;
  971.                 varY := vY;
  972.                 varZ := 0.0;
  973.                 pIVertex := NULL;
  974.                 {pIvertex := IVertices.Add(varX, varY, varZ, varDummy, varDummy, varDummy, varDummy, varDummy, varDummy, varDummy, varDummy);}
  975.                 pIvertex := IVertices.Add(varX, varY, varZ,,,,,,,,); { add a vertex. Delphi allows commas as place holder }
  976.  
  977.                 if VarValid(pIVertex) then
  978.                     VarClear(pIVertex);
  979.  
  980.                 if VarValid(IVertices) then
  981.                     VarClear(IVertices);
  982.  
  983.             end
  984.             else
  985.             begin
  986.                 TVarData(varDummy).VType := varError;
  987.                 TVarData(varDummy).VError := DISP_E_PARAMNOTFOUND;
  988.  
  989.                 IVertices := NULL;
  990.              IVertices := pIGraphic.Vertices;
  991.                 varX := vX;
  992.                 varY := vY;
  993.                 varZ := 0.0;
  994.                 pIVertex := NULL;
  995.                 {pIvertex := IVertices.Add(varX, varY, varZ, varDummy, varDummy, varDummy, varDummy, varDummy, varDummy, varDummy, varDummy);}
  996.                 pIvertex := IVertices.Add(varX, varY, varZ,,,,,,,,);
  997.  
  998.                 if VarValid(pIVertex) then
  999.                     VarClear(pIVertex);
  1000.  
  1001.                 if VarValid(IVertices) then
  1002.                     VarClear(IVertices);
  1003.             end;
  1004.         end
  1005.         else if ButtonStar.Down = true then  { drawing Point, star, box or what ever }
  1006.         begin
  1007. { !!!!!!!!!!!!!!!!!!!! FAILS AT DBAPI/DBD.cpp Line 2108 !!!!!!!!!!!!!!!!!!!!!!!!!!!!! }
  1008.             pIGraphic := Graphics.AddStar(xStart, yStart, 0.0);
  1009.         end
  1010.         else if (ButtonPickPoint.Down = true) and (PointPicked = true) then  { Pick point see if on graphic and highlite }
  1011.         begin
  1012.             try
  1013.                 StatusBar1.SimpleText := 'Count: ';
  1014.                 ThePickedResults := null;
  1015.                 ThePickedResults := TheView.PickPoint(xStart, yStart,0.1,,,,,,);
  1016.  
  1017.                 pickCount := ThePickedResults.Count;
  1018.                 if pickCount > 0 then
  1019.                 begin
  1020.                     { First deselect the current selected graphic if any }
  1021.                     if VarValid(SelectedGraphic) then
  1022.                     begin
  1023.                         PickGraphic := SelectedGraphic;
  1024.                         pProp := NULL;
  1025.                         pProp := PickGraphic.Properties;
  1026.  
  1027.                         ThePenColor := NULL;
  1028.                         ThePenColor := pProp.Item['PenColor'];
  1029.                         ThePenColor.Value :=  $000000;
  1030.                         VarClear(SelectedGraphic);
  1031.                         SelectedGraphic := NULL;
  1032.                     end;
  1033.  
  1034.                     for ii := 0 to pickCount - 1 do
  1035.                     begin
  1036.                         TheItem := ThePickedResults.Item[ii];  { must pass the parameter as if an array }
  1037.                         PickGraphic := TheItem.Graphic;
  1038.                         pProp := NULL;
  1039.                         pProp := PickGraphic.Properties;
  1040.  
  1041.                         ThePenColor := NULL;
  1042.                         ThePenColor := pProp.Item['PenColor'];
  1043.                         ThePenColor.Value :=  $0000FF;
  1044.  
  1045.                         SelectedGraphic := PickGraphic;
  1046.  
  1047.                         VarClear(TheItem);
  1048.                         VarClear(PickGraphic);
  1049.                         VarClear(ThePenColor);
  1050.                         VarClear(pProp);
  1051.  
  1052.                     end;
  1053.                     StatusBar1.SimpleText := 'Count: ' + IntToStr(pickCount);
  1054.                 end;
  1055.  
  1056.  
  1057.  
  1058.                 VarClear (ThePickedResults);
  1059.                 PointPicked := false;
  1060.             except
  1061.                on E:Exception do
  1062.                begin
  1063.                    StatusBar1.SimpleText := 'Count: 0';
  1064.                    if VarValid(ThePickedResults) then
  1065.                        VarClear(ThePickedResults);
  1066.  
  1067.                    { do nothing as not graphic found at point }
  1068.                end;
  1069.             end;
  1070.         end;
  1071.  
  1072.         PaintBoxRePaint;
  1073.         UpdateScrollParams;
  1074.  
  1075.         { clear the graphics variant }
  1076.         if not SplineStarted then
  1077.         begin
  1078.            varClear(pIGraphic);
  1079.            DragStarted := false;
  1080.         end;
  1081.     end;
  1082. end;
  1083.  
  1084. procedure TPreviewForm.ButtonLineClick(Sender: TObject);
  1085. begin
  1086.    { draws a line from mouse down to mouse up }
  1087.     SplineStarted := false;
  1088.     DragStarted := false;
  1089.  
  1090. end;
  1091.  
  1092. procedure TPreviewForm.ButtonCircleClick(Sender: TObject);
  1093. begin
  1094.     StatusBar.SimpleText := 'Click and drag with mouse to draw circle';
  1095.     SplineStarted := false;
  1096.     DragStarted := false;
  1097. end;
  1098.  
  1099. procedure TPreviewForm.ButtonSplineClick(Sender: TObject);
  1100. begin
  1101.     SplineStarted := false;
  1102.     DragStarted := false;
  1103. end;
  1104.  
  1105. procedure TPreviewForm.ButtonStarClick(Sender: TObject);
  1106. begin
  1107.    { draw a Start. Could be any point object: point, circle, star, dot, square }
  1108.     SplineStarted := false;
  1109.     DragStarted := false;
  1110. end;
  1111.  
  1112. procedure TPreviewForm.ButtonPickPointClick(Sender: TObject);
  1113. begin
  1114.     { stop the spline if it is still waiting for points }
  1115.     SplineStarted := false;
  1116.     DragStarted := false;
  1117.     PointPicked := false; { start the picking by setting to false to clear any previous click }
  1118. end;
  1119.  
  1120. procedure TPreviewForm.NewDrawing;
  1121. const
  1122.   MM_TEXT = 1;
  1123. var
  1124.     var1, var2: Variant;
  1125.     canvasRect: TRect;
  1126.     EVar, DispText: String;
  1127. begin
  1128.     if VarValid(SDKApp) then
  1129.     begin
  1130.         try
  1131.         begin
  1132.             var1 := null;
  1133.             var2 := null;
  1134.  
  1135.             {  Close any previous open drawings }
  1136.             if VarValid(TheView) then
  1137.             begin
  1138.                VarClear(TheView);
  1139.                TheView := NULL;
  1140.             end;
  1141.  
  1142.             if VarValid(SDKViews) then
  1143.             begin
  1144.                VarClear(SDKViews);
  1145.                SDKViews := NULL;
  1146.             end;
  1147.  
  1148.             if VarValid(TheDrawing) then
  1149.             begin
  1150.                 TheDrawing.Close(false);
  1151.                 VarClear(TheDrawing);
  1152.                 TheDrawing := NULL;
  1153.             end;
  1154.  
  1155.             { Get a new drawing using the SDK method }
  1156.             TheDrawing := SDKDrawings.Add;
  1157.             SDKViews := TheDrawing.Views;
  1158.             TheView := SDKViews.Add();
  1159.  
  1160.             { now that we have the particular view for the drawing, call the our
  1161.               repaint procedure to handle the painting using the SDK, we set
  1162.               the new global coordinates to accomplish the painting}
  1163.             ViewWidth := 0.0;{PaintBox1.Width;}
  1164.             ViewHeight := 0.0;{PaintBox1.Height; }
  1165.             ViewLeft := 0.0;
  1166.             ViewTop := 0.0;
  1167.  
  1168.             PaintBoxRePaint; { call the repaint procedure }
  1169.             UpdateScrollParams;
  1170.  
  1171.             DispText := 'VL: ' + FloatToStr(TheView.ViewLeft) +
  1172.              '  VT: ' + FloatToStr(TheView.ViewTop) + '  VW: ' + FloatToStr(TheView.ViewWidth) +
  1173.              '  VH: ' + FloatToStr(TheView.ViewHeight);
  1174.  
  1175.             StatusBar1.SimpleText := DispText;
  1176.         end;
  1177.         except
  1178.            on E:Exception do
  1179.                MessageDlg('Exception Occurred: ' + E.Message, mtInformation, [mbOk], 0);
  1180.         end;
  1181.     end;
  1182. end;
  1183.  
  1184. procedure TPreviewForm.PaintBox1StartDrag(Sender: TObject;
  1185.   var DragObject: TDragObject);
  1186. begin
  1187.     { unfortunately DragStart does not pass mouse coordinates so must use DragOver }
  1188. end;
  1189.  
  1190. end.
  1191.